package com.fenghongzhang.day003mvp.presenter;

import android.util.Log;

import com.fenghongzhang.day003mvp.contract.FoodContract;
import com.fenghongzhang.day003mvp.entity.Food;
import com.fenghongzhang.mvp_lib.presenter.BasePresenter;
import com.google.gson.Gson;

import java.io.IOException;

import javax.inject.Inject;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.Response;

public class FoodPresenter extends BasePresenter<FoodContract.IFoodModel,FoodContract.IFoodView> {


    private static final String TAG = "FoodPresenter";

    @Inject
    public FoodPresenter(FoodContract.IFoodModel mModel, FoodContract.IFoodView mView) {
        super(mModel, mView);
    }

    public void  getDate(){
        mModel.getFoodDate(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                Log.i(TAG, "onResponse: "+string);
                Food food = new Gson().fromJson(string, Food.class);
                mView.initAdapter(food.getData());
            }
        });
    }
}
